package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.serviceImp.UserService;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.mysql.cj.xdevapi.JsonArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("添加用户信息")
    @PostMapping("/insert")
    public int addUser(User user) {
        return userService.insert(user);
    }

    @ApiOperation("删除用户信息")
    @PostMapping("/delete")
    public int deleteUser(int id) {
        int i = 0;
        try {
            i = userService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    @ApiOperation("更新用户信息")
    @PostMapping("/update")
    public int updateUser(User user) {
        return userService.update(user);
    }

    @ApiOperation("查询所有用户信息")
    @PostMapping("/select")
    public List<User> selectAll() {
        return userService.search();
    }

}
